package com.jml.redis.一二级缓存.controller;

import com.jml.redis.一二级缓存.entity.Users;
import com.jml.redis.一二级缓存.service.UserService;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {

	@Autowired
	private EhCacheCacheManager ehCacheCacheManager;
	@Autowired
	private UserService userService;

	@RequestMapping("/multiCache")
	public Object encacheGet (String key) throws IOException {
		Users user = userService.getUser(1L);
		return user;
	}

	//清除缓存
	@RequestMapping("/encacheRemove")
	public void encacheRemove() {
		ehCacheCacheManager.getCache("userCache").clear();
	}
}
